package cn.yusei.teamTribe.dao.relation;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import cn.yusei.teamTribe.dao.relation.po.RelationPO;

@Component
public interface RelationDAO {

	final String RELATION_TABLE = "e_relation";
	final String SELECT_FIELDS = " id1, id2, create_time ";
	
	@Insert({"INSERT INTO ", RELATION_TABLE, "(id1, id2) VALUES(#{id1}, #{id2})"})
	void insert(RelationPO friendRelation);
	
	@Delete({"DELETE FROM ", RELATION_TABLE, " WHERE id1 = #{id1} AND id2 = #{id2}"})
	void delete(RelationPO friendRealation);
	
	@Select({"SELECT ", SELECT_FIELDS, " FROM ", RELATION_TABLE, " WHERE id1 = #{id} OR id2 = #{id}"})
	RelationPO[] selectById(@Param("id") long id);
	
	@Select({"SELECT ", SELECT_FIELDS, " FROM ", RELATION_TABLE, " WHERE id1 = #{id1} AND id2 = #{id2} LIMIT 1"})
	RelationPO exists(RelationPO friendRelation);
}
